import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useAuthStore = defineStore('auth', () => {
    const user = ref(null)
    const isAuthenticated = ref(false)

    const login = (username, password) => {
        // 简单模拟登录验证
        if (username === 'admin' && password === '123456') {
            user.value = { username }
            isAuthenticated.value = true
            return true
        }
        return false
    }

    const logout = () => {
        user.value = null
        isAuthenticated.value = false
    }

    return { user, isAuthenticated, login, logout }
}, {
    persist: true // 启用持久化
})